home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 493.lha / SmallIFFParseLibrary / sources / lsclip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-06  |  2.5 KB  |  92 lines

  1. /*
  2.  * Usage:       LsClip
  3.  * Function:    List the content of the clipboard.
  4.  * Description: This is an example of the standard way of using the 
  5.  *              iffparser in the most simple way, i.e. in the 
  6.  *              RAWSTEP-mode when you want to read data from the 
  7.  *              clipboard (and files).
  8.  *
  9.  * Written by:  Michael Jansson. 1990-12-08
  10.  */
  11.  
  12.  
  13. #include <libraries/iffparse.h>
  14. #include <proto/iffparse.h>
  15.  
  16. #define NAME        "Error in LsClip: "
  17. #define ERR_LIB     NAME "Could not open iffparse.library!"
  18. #define ERR_MEM     NAME "Out of memory!"
  19. #define ERR_CLIP    NAME "Could not open the clipboard!"
  20. #define ERR_OPEN    NAME "Could not open primary clip in clipboard!"
  21. #define ERR_FAILED  NAME "Failed to read the clipboard (Error Code: %ld)!\n"
  22. #define LEVEL       ". "
  23. #define SUCCESS     0L
  24.  
  25. struct Library *IFFParseBase;
  26.  
  27. void
  28. main(void)
  29. {
  30.     struct ContextNode *chunk = NULL;
  31.     struct IFFHandle *iff = NULL;
  32.     UBYTE buf1[5], buf2[5];
  33.     long i, error;
  34.     
  35.  
  36.     /* Open all the stuff that is needed! */
  37.     if ((IFFParseBase=OpenLibrary("iffparse.library", 0L))==NULL) {
  38.         puts(ERR_LIB);
  39.         goto die;
  40.     }
  41.     if ((iff = AllocIFF())==NULL) {
  42.         puts(ERR_MEM);
  43.         goto die;
  44.     }
  45.     if ((iff->iff_Stream=(ULONG)OpenClipboard(0L))==0L) {
  46.         puts(ERR_CLIP);
  47.         goto die;
  48.     }
  49.     InitIFFasClip(iff);
  50.     if (OpenIFF(iff, IFFF_READ)) {
  51.         puts(ERR_OPEN);
  52.         goto die;
  53.     }
  54.  
  55.     /* Let's do it...*/
  56.     do {
  57.         switch(error=ParseIFF(iff, IFFPARSE_RAWSTEP)) {
  58.         case IFFERR_EOC:/* End of a context (chunk). */
  59.             break;
  60.         case IFFERR_EOF:/* End of the stream. */
  61.             goto die;
  62.             break;
  63.         case SUCCESS:   /* Entering a new context (chunk). */
  64.             chunk = CurrentChunk(iff);
  65.             for (i=0; i<iff->iff_Depth; i++)
  66.                 printf(LEVEL);
  67.             printf("%s %ld %s\n", 
  68.                 IDtoStr(chunk->cn_ID, buf1), 
  69.                 chunk->cn_Size, 
  70.                 IDtoStr(chunk->cn_Type, buf2));
  71.             break;
  72.         default:        /* Everything else is a genuin error. */
  73.             printf(ERR_FAILED, error);
  74.             goto die;
  75.             break;
  76.         }
  77.     } while (TRUE);
  78.  
  79.  
  80.     /* Make a clean exit. */
  81. die:
  82.     if (iff) {
  83.         CloseIFF(iff);
  84.         if (iff->iff_Stream)
  85.            CloseClipboard((struct ClipboardHandle *)iff->iff_Stream);
  86.         FreeIFF(iff);
  87.     }
  88.     if (IFFParseBase)
  89.         CloseLibrary(IFFParseBase);
  90.     exit(0);
  91. }
  92.